// 绑定类型
swig.setFilter('bindType', function (type) {
  var map = [null, '业主', '家庭成员', null, '租客'];
  return map[type] || '';
});

// 绑定房屋
(function () {
  if (location.pathname !== '/bind/house') {
    return false;
  }

  ClientBridge.setMenus([{
    name: '绑定记录',
    content: '/bind/records'
  }]);

  // 切换身份
  $(document).on('click', '.item.type .flexbox > .item', function () {
    $(this).addClass('selected').siblings().removeClass('selected');
    $('.target').html($(this).text());
  });

  // 生成二维码
  $(document).on('click', '.item.gencode', function () {
    var room = $('[data-room]').data('room');
    if (!room) {
      return Modal.confirm({
        message: '您还没有选择房屋，现在去选择？',
        callback: function () {
          location.href = '/bind/project';
        }
      });
    }
    location.href = '/bind/qrcode?identity=' + $('.item.type .item.selected').data('identity');
  });
})();

// 绑定记录
(function () {
  if (location.pathname !== '/bind/records') {
    return false;
  }

  // 更多订单
  loadMoreFactory({
    size: 20,
    url: '/bind/ajax/records',
    panel: '#records',
    template: '#recordsTempl'
  });
})();
